#!/usr/bin/python
# -*- coding: UTF-8 -*-

import MySQLdb
import python-sqlite

# 打开数据库连接
db = MySQLdb.connect("localhost","root","123456","tang_poetry" )

# 使用cursor()方法获取操作游标 
cursor = db.cursor()
<<<<<<< HEAD:linuxDoc/mysql-select.py

=======
sql = "select title, (select name from poets where poetries.poet_id = poets.id), content from poetries;"
>>>>>>> 870eedbb689e0e4032b93f016abeb7ae764a5bee:pythonDoc/mysql-select.py
try:
	cursor.execute("select * from poetries where poet_id in (select name from poets);")
	results = cursor.fetchall()
	for row in results:
		title = row[0]
		author = row[1]
		content = row[2]
<<<<<<< HEAD:linuxDoc/mysql-select.py
		title = row[3]
		
		# query author                 
		poets_sql = "select name from poets where poet_id = 272;"
                cursor.execure()
                results = cursor.fetchall()
                print results
		# author = results[0]
                # print "author name %s " % author
		# print "| %s ,%s, %s, %s |" % ( ids, poet_id, content, title)
=======
		python-sqlite.insertDatas((title, author, content))
		print "| %s / %s / %s |" % (title, author, content)
>>>>>>> 870eedbb689e0e4032b93f016abeb7ae764a5bee:pythonDoc/mysql-select.py
except:
	print "error: unable to fecth data"
db.close()

